<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
      xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../assert/css/font.css" th:href="@{/assert/css/font.css}"/>
    <link rel="stylesheet" href="../../../assert/css/plugin/chosen/chosen.css"
          th:href="@{/assert/css/plugin/chosen/chosen.css}"/>
    <link href="../../../assert/css/animate.min.css" rel="stylesheet" th:href="@{/assert/css/animate.min.css}">
    <link href="../../../assert/css/plugin/toastr/toastr.min.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/toastr/toastr.min.css}">
    <link href="../../../assert/css/plugin/jsTree/themes/default/style.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/jsTree/themes/default/style.css}">
    <link href="../../../assert/js/layui/css/layui.css" rel="stylesheet"
          th:href="@{/assert/js/layui/css/layui.css}" media="all">
    <link href="../../../assert/css/loaders.css" rel="stylesheet"
          th:href="@{/assert/css/loaders.css}">
    <link rel="stylesheet" href="../../../assert/css/bootstrap.min.css" th:href="@{/assert/css/bootstrap.min.css}"/>
    <link href="../../../assert/css/plugin/bootstrap-table/bootstrap-table.min.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/bootstrap-table/bootstrap-table.min.css}">
    <link rel="stylesheet" href="../../../assert/css/jquery-ui.css" th:href="@{/assert/css/jquery-ui.css}"/>
    <link rel="stylesheet" href="../../../assert/js/bootstrap-fileinput/css/fileinput.min.css"
          th:href="@{/assert/js/bootstrap-fileinput/css/fileinput.min.css}"/>
    <link href="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css" rel="stylesheet"
          th:href="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css}"/>
    <link rel="stylesheet" href="../../../assert/css/index.css"
          th:href="@{/assert/css/index.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"/>
    <style>
        .table_msg {
            width: 100%;
            border: 1px solid #e4eaec;
            padding: 0px 10px;
            position: relative;
            top: 6px;
            background: #ddd;
        }

        .layui-form-switch {
            width: 48px;
        }

        .search_group label.control-label {
            width: 85px;
        }

        .remarkBox .jqx-validator-error-label {
            top: 115px !important;
        }

        .form-group {
            display: inline-block;
            width: 100%;
        }

        #importModal .form-group label {
            text-align: right;
            margin-top: 6px;
        }
    </style>
</head>
<body class="oneStyle">
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="model_left">
            <!--<h4 class="model_title">质检模型</h4>-->
            <div class="search_box">
                <input type="text" style="width: 174px;padding:1px 5px;" autocomplete="off"><span
                    class="fa fa-search fa_btn"
                    id="searchMenu"></span>
            </div>

            <div id="jstree" class="scrollbar">

            </div>
        </div>
        <div class="model_right">
            <div class="tools_bar">
                <div class="pull-left">
                    <a href="#" class="btn btn-default active" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 隐藏</a>
                    <a href="#" class="btn btn-default active" id="refresh"><i class="fa fa-refresh"></i> 刷新</a>
                    <a href="#" class="btn btn-default active" id="btnAdd" title="添加关键词"><i class="fa fa-plus"></i>
                        添加</a>
                    <a href="#" class="btn btn-default active" id="btnEdit" title="编辑关键词"><i class="fa fa-pencil"></i>
                        编辑</a>
                    <a href="#" class="btn btn-default active" id="btnDel" title="删除关键词"><i class="fa fa-remove"></i>
                        删除</a>
                    <a href="#" class="btn btn-default active" id="btnAllAdd" title="导入关键词"><i class="fa fa-plus"></i>
                        导入</a>
                    <a href="#" style="margin-left:20px" class="btn btn-default active" id="btnStart" title="启用关键词"><i
                            class="fa fa-long-arrow-up stateGreen"></i> 启用</a>
                    <a href="#" class="btn btn-default active" id="btnStop" title="停用关键词"><i
                            class="fa fa-long-arrow-down stateRed"></i> 停用</a>

                </div>
            </div>
            <div class="search on">
                <div class="search_group">
                    <label class="control-label">分类名称：</label>
                    <div class="control-inline">
                        <input type="text" id="typeName" value="" class="form-control search_input" autocomplete="off"
                               disabled>
                    </div>
                </div>
                <div class="search_group">
                    <label class="control-label">关键词名称：</label>
                    <div class="control-inline">
                        <input type="text" id="modelname" value="" class="form-control search_input" autocomplete="off">
                    </div>
                </div>
                <div class="search_group">
                    <label class="control-label">状态：</label>
                    <div class="control-inline">
                        <select type="text" id="state" value=""
                                class="form-control search_input chosen-select"></select>
                    </div>
                </div>
                <div class="search_group">
                    <label class="control-label">创建时间：</label>
                    <div class="control-inline">
                        <input placeholder="开始日期" class="form-control layer-date search_input" id="start"
                               autocomplete="off"> -
                        <input placeholder="结束日期" class="form-control layer-date search_input" id="end"
                               autocomplete="off">
                    </div>
                </div>
                <div class="search_group">
                    <button id="search" class="btn  btn-primary">查询</button>
                    <button id="searchAll" class="btn  btn-primary">全查询</button>
                    <button id="reset" class="btn  btn-default">重置</button>
                    <button id="export" class="btn  btn-default">导出</button>
                </div>
            </div>
            <table id="myTable"></table>
        </div>
    </div>
</div>
<!--添加关键词-->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:900px !important;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">添加关键词</h4>
            </div>
            <div class="modal-body">
                <form method="post" class="form-horizontal" id="addModelForm">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;">分类:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <input name="note" class="form-control" id="typeAdd" disabled data-id="1"/>
                        </div>

                    </div>
                    <div class="form-group remarkBox">
                        <label for="" class="col-sm-3 control-label" style="width:21%;"><span class="respan">*</span>关键词:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <span style="color: #ef9407;">支持汉字、英文、数字组合，可同时添加多个关键词，请用英文输入法“,”（逗号）隔开，关键词内不能包含符号与空格，最后一个词尾不用加标点符号。
例：欢迎,您好,A卡套餐</span>
                            <textarea name="note" class="form-control" style="height:70px;" id="keyAdd"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="save">保存</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<!--编辑关键词-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width:900px !important;">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">编辑关键词</h4>
            </div>
            <div class="modal-body">
                <form method="post" class="form-horizontal" id="editModelForm">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;">分类:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <input name="note" class="form-control" id="typeEdit" disabled/>
                        </div>

                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label" style="width:21%;"><span class="respan">*</span>关键词:</label>
                        <div class="col-sm-8" style="width: 70.6%;">
                            <input name="note" class="form-control" id="keyEdit"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="saveEdit">保存</button>
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>
<!--删除确认框-->
<div class="modal fade" id="delModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center">
                        <span class="fa fa-question-circle"></span>
                        <span id="delName"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="delBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--上线/下线确认框-->
<div class="modal fade" id="startModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">上线</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center">
                        <div>
                            <div class="tipBox"></div>
                        </div>
                        <span class="fa fa-question-circle"></span>
                        <span id="type"></span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="startBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--导入关键词-->
<div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">导入</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label"><span class="respan">*</span>省份：</label>
                        <div class="col-sm-8">
                            <select name="province_code" id="proModal" data-code="pro"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label"><span class="respan">*</span>上传：</label>
                        <div class="col-sm-8" id="uploadDiv">

                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label"></label>
                        <div class="col-sm-8">
                            <button type="button" class="btn btn-outline btn-default"
                                    onclick="window.location.href=basePath+'app/template/重点关键词导入模板.xlsx';">
                                点击获取模板文件
                            </button>
                            <div>
                                <!--<ul class="importTips">-->
                                <!--<li><span>●</span>不选省份则默认导入到集团中。</li>-->
                                <!--</ul>-->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="importBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--删除分类确认框-->
<div class="modal fade" id="delModalCon" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">删除</h4>
                </div>
                <div class="modal-body">
                    <div style="text-align: center;color:#ff0000;margin-bottom:10px;" id="delText"></div>
                    <div style="text-align: center"><span class="fa fa-question-circle"></span>确定要删除 <span
                            id="delNameCon"></span> 吗？
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="delConBtn">确定</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--添加分类模态框-->
<div class="modal fade" id="addTypeModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <form method="post" class="form-horizontal" id="addTypeForm">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span
                            aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                    <h4 class="modal-title">添加分类</h4>
                </div>
                <div class="modal-body">
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label">省份:</label>
                        <div class="col-sm-8">
                            <select name="provinceid" id="proTypeModal" data-code="pro"></select>
                            <input type="text" class="form-control selectInput" id="proTypeModalAddInput"
                                   autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label">上级分类:</label>
                        <div class="col-sm-8">
                            <input type="text" name="name" id="typeParentModal" class="form-control" autocomplete="off"
                                   disabled>
                            <!--<select name="provinceid" id="typeParentModal"></select>-->
                            <!--<input type="text" class="form-control selectInput" id="typeParentModalAddInput"-->
                            <!--autocomplete="off">-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="" class="col-sm-3 control-label"><span class="respan">*</span>分类名称:</label>
                        <div class="col-sm-8">
                            <input type="text" name="name" id="modelTypeName" class="form-control" autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" id="addTypeBtn">保存</button>
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                </div>
            </form>
        </div>
    </div>
</div>
<form action="" id="exportForm" class="hidden" method="post" target="_self">
    <input type="text" name="id_tree">
    <input type="text" name="term_name">
    <input type="text" name="term_status">
    <input type="text" name="create_time_start">
    <input type="text" name="create_time_end">
</form>
<input type="text" id="proId" class="hidden">
<a id="basePath" th:href="@{/}"></a>
<script src="../../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/bootstrap.min.js" th:src="@{/assert/js/bootstrap.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/bootstrap-table-mobile.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/bootstrap-table-mobile.min.js}"></script>
<script src="../../../assert/js/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"
        th:src="@{/assert/js/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<script src="../../../assert/js/plugin/toastr/toastr.min.js"
        th:src="@{/assert/js/plugin/toastr/toastr.min.js}"></script>
<script src="../../../assert/js/base.js"
        th:src="@{/assert/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/jquery-ui.min.js" th:src="@{/assert/js/jquery-ui.min.js}"></script>
<script src="../../../assert/js/plugin/layer/laydate/laydate.js"
        th:src="@{/assert/js/plugin/layer/laydate/laydate.js}"></script>
<script src="../../../assert/js/changeTime.js"
        th:src="@{/assert/js/changeTime.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/plugin/jsTree/jstree.min.js"
        th:src="@{/assert/js/plugin/jsTree/jstree.min.js}"></script>
<script src="../../../assert/js/plugin/chosen/chosen.jquery.js"
        th:src="@{/assert/js/plugin/chosen/chosen.jquery.js}"></script>
<script src="../../../assert/js/layui/layui.js" th:src="@{/assert/js/layui/layui.js}"></script>
<script src="../../../assert/js/common.js"
        th:src="@{/assert/js/common.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js}"></script>
<script src="../../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js}"></script>
<script src="../../../assert/js/bootstrap-fileinput/js/fileinput.min.js"
        th:src="@{/assert/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script src="../../../assert/js/bootstrap-fileinput/js/locales/zh.js"
        th:src="@{/assert/js/bootstrap-fileinput/js/locales/zh.js}"></script>
<script>
    //项目名称
    var basePath = $("#basePath").attr("href");
    var json = [];
    var TableInit = function () {
        var oTableInit = new Object();
        var url = bs.getSysConfig("ZDYW_KEY").value + '/term/queryTerm';
        var height = ($(window).height() -$(".tools_bar").height()-9-$(".search").height()-40);
        //初始化Table
        oTableInit.Init = function () {
            $('#myTable').bootstrapTable("destroy");
            $('#myTable').bootstrapTable({
                url: url,         //请求后台的URL（*）
                method: 'post',                      //请求方式（*）
                height:height,
                cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                sortable: false,                     //是否启用排序
                sortOrder: "asc",                   //排序方式
                responseHandler: function (res) {
                    tools.tableData = res.data.rows;
                    return {
                        "total": res.data.total,//总页数
                        "rows": res.data.rows   //数据
                    };
                },
                pagination: true, // 是否显示分页（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,                       //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                contentType: "application/x-www-form-urlencoded",
                strictSearch: true,
                showColumns: false,                  //是否显示所有的列
                showRefresh: false,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "no",                     //每一行的唯一标识，一般为主键列
                showToggle: false,                    //是否显示详细视图和列表视图的切换按钮
                cardView: false,                    //是否显示详细视图
                detailView: false,
                cellStyle: {
                    css: {"background-color": "#fff"}
                },//是否显示父子表
                queryParams: function (params) {
                    var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                        pageSize: params.limit,   //页面大小
                        pageNum: params.offset / params.limit + 1,  //偏移量
                        id_tree: $("#typeAdd").attr("data-id"),
                        term_name: $.trim($("#modelname").val()),//名称
                        term_status: $("#state").val(),//状态
                        create_time_start: $("#start").val(),//开始日期
                        create_time_end: $("#end").val() //结束日期
                    };
                    return temp;
                },
                columns: [
                    {
                        checkbox: true, // 显示一个勾选框
                        align: 'center' // 居中显示
                    },
                    {
                        align: "center",
                        halign: "center",
                        title: '序号',//标题  可不加
                        width: 60,
                        field: 'number',
                        formatter: function (value, row, index) {
                            var getOptions = $("#myTable").bootstrapTable('getOptions');
                            var pagenum = getOptions.pageNumber;
                            var pagesize = getOptions.pageSize;
                            var st = (pagenum - 1) * pagesize;
                            return (st + index + 1) + "";
                        }
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'province',
                        title: '省份'
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'tree_name',
                        title: '关键词分类'
                    },
                    {
                        align: "center",
                        halign: "center",
                        field: 'term_name',
                        title: '关键词'
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'term_status',
                        title: '状态',
                        formatter: function (value, row, index) {
                            var str = "";
                            var color = "#000";
                            if (value == "1") {
                                color = "stateGreen";
                            }
                            str = bs.changeState(value, tools.stateArr);
                            return "<span class='" + color + "'>" + str + "</span>";
                        }
                    }, {
                        align: "center",
                        halign: "center",
                        field: 'create_time',
                        title: '创建时间'
                    }
                ],
                onLoadSuccess: function (data) {  //加载成功时执行
                    resize.me();
                    if (!data.total || data.total == 0) {
                        var src = basePath + "/assert/image/nodata.png";
                        $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                    }
                },
                onLoadError: function () {  //加载失败时执行
                    var src = basePath + "/assert/image/nodata.png";
                    $(".no-records-found").find("td").html('<img src="' + src + '" th:src="@{/assert/image/nodata.png}" style="width:165px;" alt="">');
                },
                formatLoadingMessage: function () {
                    return '<div class="loaded">' +
                        '<div class="loader">' +
                        '<div class="loader-inner line-scale-pulse-out">' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '<div></div>' +
                        '</div>' +
                        '</div>' +
                        '</div>' +
                        '<div>请稍等，数据正在加载中...</div>';
                }
            });
        };
        return oTableInit;
    };
    var menu = {
        init: function () {
            menu.render();
            menu.addEditTree();
        },
        render: function (node) {
            var jstree = $("#jstree");
            var code = $("#spanId", parent.document).attr("data-procode");
            jstree.jstree("destroy");
            jstree.data('jstree', false).empty();
            jstree.jstree({
                "core": {
                    "animation": false,
                    "multiple": false,
                    "check_callback": true,
                    'data': function (obj, callback) {
                        $.ajax({
                            type: "POST",
                            url: bs.getSysConfig("ZDYW_KEY").value + '/tree/getBuildTree',
//                            dataType: "json",
//                            contentType: 'application/json',
                            data: {"province_code": code},
                            success: function (data) {
                                var result = data.data;
                                if (result != null) {
                                    var arr = [];
                                    arr.push(result);
                                    callback.call(this, menu.loopMenu(arr));
                                }
                                menu.changeMenu();
                                menu.search();
                            }
                        });
                    }
                },
                "types": {
                    "default": {
                        "icon": "jstree-folder"
                    },
                    "html": {
                        "icon": "jstree-file"
                    }
                },
                "plugins": ["types", "search", "unique", "contextmenu"],
                'contextmenu': {
                    'items': menu.customMenu     //每个节点都会调用这个函数
                }
            }).bind('loaded.jstree', function (e, data) {
                jstree.jstree("deselect_all", true);
                var obj = jstree.jstree("get_node", node);
                jstree.jstree('select_node', obj, true);
                $("li[aria-selected='true']").click();
                $("#typeAdd,#proId").attr("data-id", $(".jstree-container-ul>li").attr("id"));//页面初始化加载对应省份的关键词
                tools.tableRefresh();
            });
        },
        customMenu: function (node) {
            var items = {
                'add': {
                    'label': '新增分类',
                    'action': function (data) {
                        var inst = $.jstree.reference(data.reference),
                            obj = inst.get_node(data.reference);
                        var id = obj.original.id;
                        var name = obj.original.tree_name;
                        $("#typeParentModal").parents(".form-group").show();
                        $("#proTypeModal").parents(".form-group").hide();
                        $("#addTypeForm")[0].reset();
                        $("#addTypeModal").modal("show");
                        $("#addTypeModal").attr("data-code", "add");
                        $("#addTypeForm").find(".modal-title").html("添加分类");
                        $("#addTypeModal").attr("data-id", id);

                        $("#typeParentModal").val(name);
                    }
                },
                'addModel': {
                    'label': '添加关键词',
                    'action': function (data) {
                        $("#btnAdd").click();
                    }
                },
                'edit': {
                    'label': '编辑',
                    'action': function (data) {
                        var inst = $.jstree.reference(data.reference),
                            obj = inst.get_node(data.reference);
                        $("#addTypeModal").modal("show");
                        $("#addTypeModal").attr("data-code", "edit");
                        $("#addTypeForm").find(".modal-title").html("编辑分类");
                        $("#proTypeModal").parents(".form-group").hide();
                        var parentid = obj.original.id_parent;
                        var id = obj.original.id;
                        var name = obj.original.tree_name;
                        var parent = $("#jstree").jstree("get_node", parentid);
                        var parentname = parent.original.tree_name;
                        $("#addTypeModal").attr("data-id", id);
                        $("#modelTypeName").val(name);
                        $("#typeParentModal").val(parentname);
                    }
                },
                'delete': {
                    'label': '删除',
                    'action': function (data) {
                        var inst = $.jstree.reference(data.reference),
                            obj = inst.get_node(data.reference);
                        $("#delModalCon").modal("show");
                        $("#delNameCon").html(obj.text).css("color", "rgb(50, 136, 226)");
                        $("#delConBtn").unbind("click").on("click", function () {
                            $.ajax({
                                type: "post",
                                url: bs.getSysConfig("ZDYW_KEY").value + '/tree/removeTreeById',
                                dataType: "json",
                                data: {
                                    id_tree: obj.id
                                },
                                success: function (result) {
                                    var msg = result.message;
                                    if (result.code == 1) {
                                        $("#delText").html("");
                                        $("#typeAdd").attr("data-id", "1").val("");//删除后清除已选中id
                                        $("#typeName").val("");
                                        toastrCog.success(msg, 3000);
                                        menu.render();
                                    } else {
                                        $("#delText").html("");
                                        toastrCog.error(msg, 3000);
                                    }
                                }
                            });
                            $("#delModalCon").modal("hide");
                        });
                    }
                }

            };

            var code = menu.checkData(node.id);
            var parentid = node.original.id_parent;
            if (parentid == 0) {//如果parentid是0 则是根节点
                delete items.edit;  //如果是根节点 删除编辑分类方法
                delete items.delete;  //如果是根节点 删除 删除分类方法
                delete items.addModel;  //如果是根节点 删除新增关键词方法
                delete items.add;//如果是根节点 删除新增分类方法
            } else if (parentid == 1) {
                delete items.edit;  //如果是省份 删除编辑方法
                delete items.addModel;  //如果是省份 删除新增模型方法
                delete items.delete;  //如果是根节点 删除 删除分类方法
            } else {
                if (code == 1) { //如果是1 则只能添加关键词
                    delete items.add;
                } else if (code == 2) { //如果是2 则只能添加关键词分类
                    delete items.addModel;
                }
            }
            return items;
        },
        checkData: function (id) {
            var msg = "";
            var params = {"id_tree": id};
            $.ajax({
                type: "post",
                url: bs.getSysConfig("ZDYW_KEY").value + '/tree/isAddTerm',
                dataType: "json",
                data: params,
                async: false,
                success: function (result) {
                    msg = result.data;
                }
            });
            return msg;
        },
        loopMenu: function (array) {//递归 修改树节点属性
            if (array && array.length > 0) {
                for (var i = 0; i < array.length; i++) {
                    var children = array[i]["children"];
                    array[i]["id"] = array[i]["id_tree"];
                    array[i]["text"] = array[i]["tree_name"];
                    array[i]["parentid"] = array[i]["id_parent"];
                    if (children.length <= 0) {
                        array[i].type = "html"
                    } else {
//                        if(i<=1){
                        array[i].state = {"opened": "true"};
//                        }
                    }
                    if (children) {
                        menu.loopMenu(children);
                    }
                }
                return array;
            } else {
                return []
            }
        },
        changeMenu: function () {//树菜单切换事件
            $('#jstree').unbind("changed.jstree").on("changed.jstree", function (e, data) {
                var val = data.selected;
                if (val.length > 0) {
                    var selectNode = $("#jstree").jstree("get_node", data.selected);
                    $("#typeAdd").attr("data-id", val).val(selectNode.original.tree_name);
                    $("#typeName").val(selectNode.original.tree_name);
                }
                tools.tableRefresh();
            });
        },
        search: function () {
            $("#searchMenu").unbind("click").on("click", function () {
                $("#jstree").jstree(true).search($.trim($(".search_box input").val()));
                menu.scrollSearch($("#jstree"));
            });
            $(".search_box input").unbind("keyup").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    $("#jstree").jstree(true).search($.trim($(".search_box input").val()));
                    menu.scrollSearch($("#jstree"));
                }
            })
        },
        scrollSearch: function (elem) {
            if (elem.find(".jstree-search").length > 0) {
                var odiv = elem.find(".jstree-search").eq(0)[0];
                var top = odiv.offsetTop;
                var height = odiv.offsetHeight;
                var elemTop = elem[0].scrollTop;
                //获取当前屏幕大小
                var size = elem.height();
                //加上元素本身的高度，是元素全部出现事件
                if ((top + height) < (elemTop + size) && (top + height) > elemTop) {

                } else {
                    elem.animate({scrollTop: top - 70}, "slow");
                }
            }
        },
        refresh: function () {
            var tree = $('#jstree');
//            tree.jstree(true).settings.core.data = menu.loopMenu(menu.getMenuData()); // 新数据
            tree.jstree(true).refresh(); //刷新树
        },
        addEditTree: function () {
            $("#addTypeBtn").on("click", function () {
                $("#addTypeForm").jqxValidator("validate");
            });
            $("#addTypeForm").on("validationSuccess", function (event) {
                var url = "";
                var code = $("#addTypeModal").attr("data-code");
                var params;
                if (code == "add") {
                    url = bs.getSysConfig("ZDYW_KEY").value + '/tree/insertTree';
                    var parentid = $("#addTypeModal").attr("data-id")
                    params = {
                        "id_parent": parentid,
                        "tree_name": $("#modelTypeName").val()
                    };
                } else if (code == "edit") {
                    url = bs.getSysConfig("ZDYW_KEY").value + '/tree/updateTreeById';
                    params = {
                        id_tree: $("#addTypeModal").attr("data-id"),
                        tree_name: $("#modelTypeName").val()
                    };
                }
                $.ajax({
                    type: "post",
                    url: url,
                    dataType: "json",
                    contentType: "application/json",
                    data: JSON.stringify(params),
                    success: function (result) {
                        var msg = result.message;
                        var code = result.code;
                        if (code == 1) {
                            menu.refresh();
                            toastrCog.success(msg, 1000);
                        } else {
                            toastrCog.error(msg, 1000)
                        }
                        $("#addTypeModal").modal("hide");
                    }
                });
            });
        }
    };
    var resize = {
        init: function () {
            resize.me();
            $(window).resize(function () {
                resize.me();
            })
        },
        me: function () {
            var winW = $(window).width();
            var winH = $(window).height();
            $(".ibox").width(winW - 20);
            $(".ibox").height(winH - 25);
            $("#jstree").height(winH - 60);
            $(".model_right").width(winW - 240);
            bs.autoTableHeight($('#myTable'),winH -$(".tools_bar").height()-22-$(".search").height())
        }
    };
    var tools = {
        maxTextLength: null,
        ruleUrl: "",
        tableData: [],
        ruleTableData: [],
        classifyArr: [],
        stateArr: [
            {
                name: "全部",
                value: ""
            }
        ],
        seatIdArr: [],
        seatAllArr: [],
        proArr: [],//存放省份信息
        url: null,
        init: function () {
            tools.getConfig();
            tools.selectProvince();
            tools.selectInit();
            tools.tabSearch();
            tools.enterSearch();
            tools.search();
            tools.reset();
            tools.refresh();
            tools.addModel();
            tools.editModel();
            tools.saveModel();
            tools.delModel();
            tools.startModel();
            tools.stopModel();
            tools.export();
            importfile.init();
            $("#addModal").on("hidden.bs.modal", function () {
                var form = $("#addModelForm");
                tools.hideLabel(form, '#keyAdd');
                $("#keyAdd").removeClass("jqx-validator-error-element");
                $(".jqx-validator-hint").remove();
            });
            $("#editModal").on("hidden.bs.modal", function () {
                var form = $("#editModelForm");
                tools.hideLabel(form, '#keyEdit');
            });
            $("#addTypeModal").on("hidden.bs.modal", function () {
                var form = $("#addTypeForm");
                tools.hideLabel(form, '#proTypeModalAddInput');
                tools.hideLabel(form, '#modelTypeName');
                $("#remarkTypeAdd").removeClass("jqx-validator-error-element");
                $(".jqx-validator-error-label").remove();
            });
            $(".form-horizontal").on("click", "#radio_box input", function () {
                $(this).prop("checked", true);
                $(this).siblings("input").prop("checked", false);
            })

        },
        selectProvince: function () {//省份下拉框初始化
            tools.proArr = bs.getProvince();
            var arr = tools.proArr;
            arr.shift();
            arr.unshift({name: "请选择", value: "", id: ""});
            bs.selectDown($("#proModal"), arr, "", '100%');
        },
        hideLabel: function (form, input) {
            form.jqxValidator('hideHint', input);
        },
        getConfig: function () {
            var maxNum = bs.getSysConfig("NAME_LIMIT");
            var num = 50;
            if (maxNum) {
                num = maxNum.value
            }
            tools.maxTextLength = num;
            tools.url = bs.getSysConfig("ZDYW_KEY").value;
        },
        selectInit: function () {
            bs.dataTime("#start", "#end");
            tools.getState();
            tools.getTestState();
            bs.selectDown($("#modelTypeEdit"), tools.classifyArr, "", '100%');
            bs.selectDown($("#tagTypeCopy"), tools.classifyArr, "", "100%");
        },
        selectChange: function ($elem, $input) {
            $elem.on("change", function (event, sel) {
                $input.val(sel.selected);
                if (sel.selected == "") {
                    $input.next().html("").css("display", "none !important");
                }
            });
        },
        getState: function () {
            tools.stateArr = bs.getDownData("key_status");
            bs.selectDown($("#state"), tools.stateArr);
        },
        getTestState: function () {
            tools.testStateArr = bs.getDownData("model_is_test");
        },
        changeState: function (value) {
            var str = "";
            for (var i = 0; i < tools.stateArr.length; i++) {
                if (value == tools.stateArr[i].value) {
                    str = tools.stateArr[i].name
                }
            }
            return str;
        },
        tabSearch: function () {
            var search = $(".search");
            $("#btnSearch").on("click", function () {
                if (search.hasClass("on")) {
                    search.slideUp();
                    search.removeClass("on");
                    $("#btnSearch").html('<i class="fa fa-filter"></i> 查询').attr("title", "显示查询条");
                } else {
                    search.slideDown();
                    search.addClass("on");
                    $("#btnSearch").html('<i class="fa fa-filter"></i> 隐藏').attr("title", "隐藏查询条");
                }

            });
        },
        search: function () {
            $("#search").on("click", function () {
                tools.tableRefresh();
            });
            $("#searchAll").on("click", function () {
                $("#typeName").val("");
                $("#typeAdd").attr("data-id", $("#proId").attr("data-id")).val("");//清除已选中id
                $("#jstree").jstree("deselect_all", true);
                tools.tableRefresh();
            });

        },
        tableRefresh: function () {
            $("#myTable").bootstrapTable('refreshOptions', {pageNumber: 1});
            $("#myTable").bootstrapTable('refresh');
        },
        enterSearch: function () {
            $("body").on("keyup", function (e) {
                var code = e.charCode || e.keyCode;
                if (code == 13) {
                    //此处编写用户敲回车后的代码
                    tools.tableRefresh();
                }
            })
        },
        reset: function () {
            $("#reset").on("click", function () {
                bs.resetSearch($(".search"));
                if ($("#laydate_box").length > 0) {
                    bs.resetTimeElems("#start", "#end");
                }
                tools.tableRefresh();
            })
        },
        resetSelect: function ($obj) {
            $obj.val("");
            $obj.trigger("chosen:updated");
        },
        refresh: function () {
            $("#refresh").on("click", function () {
                $("#myTable").bootstrapTable('refresh');
            })
        },
        addModel: function () {
            $("#addModal").on("hide.bs.modal", function () {
                $("#keyAdd").val("");
            });
            $("#btnAdd").on("click", function () {
                var id = $("#typeAdd").attr("data-id");
                if (id == "" || id == "1") {
                    toastrCog.error("请选择一个分类！");
                    return
                } else {
                    var selectNode = $("#jstree").jstree("get_node", id);
                    var parentid = selectNode.original.parentid;
                    if (parentid == 1) {
                        toastrCog.error("请选择一个分类！");
                        return
                    }
                }
                $("#addModal").modal("show");
            })
        },
        saveModel: function () {
            $("#save").on("click", function () {
                $("#addModelForm").jqxValidator("validate");
            });
            $("#addModelForm").on("validationSuccess", function (event) {
                var obj = {};
                obj.id_tree = $("#typeAdd").attr("data-id");
                obj.term_nameStr = $("#keyAdd").val();
                var nameArr = obj.term_nameStr.split(",");
                var isSame = bs.isRepeat(nameArr);
                if (isSame) {
                    toastrCog.error("存在重复关键词！");
                    return;
                }
                $.ajax({
                    url: bs.getSysConfig("ZDYW_KEY").value + "/term/saveTerms",
                    type: "post",
                    data: obj,
                    success: function (result) {
                        var msg = result.message;
                        var code = result.code;
                        var data = result.data;
                        if (code == 1) {
                            tools.tableRefresh();
                            if (data && data.length > 0) {
                                var tip = "该省份下关键词";
                                for (var i = 0; i < data.length; i++) {
                                    tip += data[i] + ",";
                                }
                                tip = tip.substr(0, tip.length - 1);
                                tip += "已经存在!";
                                toastrCog.success(tip, 5000);
                            } else {
                                toastrCog.success("添加成功", 2000)
                            }
                        } else {
                            toastrCog.error(msg, 3000);
                        }
                        $("#addModal").modal("hide");
                    }
                });
            });
        },
        editModel: function () {
            $("#btnEdit").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要编辑的数据！", 3000);
                } else if (selectArr.length > 1) {
                    toastrCog.error("请选择一条要编辑的数据！", 3000);
                } else if (selectArr[0].term_status == 1) {
                    toastrCog.error("关键词已启用，无法编辑。要编辑关键词,请先停用关键词。", 3000);
                } else {
                    $("#editModal").modal("show");
                    $("#typeEdit").val(selectArr[0].tree_name);
                    $("#keyEdit").val(selectArr[0].term_name);
                    $("#editModal").attr({
                        "data-id": selectArr[0].id_term,
                        "data-code": selectArr[0].province_code,
                        "data-name": selectArr[0].term_name
                    });
                }
            });
            $("#saveEdit").on("click", function () {
                $("#editModelForm").jqxValidator("validate");
            });
            $("#editModelForm").on("validationSuccess", function (event) {
                var id = $("#editModal").attr("data-id");
                var name = $("#editModal").attr("data-name");
                if ($("#keyEdit").val() != name) {
                    $.ajax({
                        type: "post",
                        url: bs.getSysConfig("ZDYW_KEY").value + "/term/updateById",
                        dataType: "json",
//                    contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                        data: {
                            id_term: id,
                            term_name: $("#keyEdit").val()
                        },
                        success: function (data) {
                            if (data.code == 1) {
                                $("#myTable").bootstrapTable('refresh');
                                toastrCog.success(data.message, 1000)
                            } else {
                                toastrCog.error(data.message, 3000)
                            }
                        }
                    })
                }
                $("#editModal").modal("hide");

            });
        },
        delModel: function () {
            $("#btnDel").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要删除的数据！", 3000);
                } else {
                    var delArr = [];
                    for (var i = 0; i < selectArr.length; i++) {
                        if (selectArr[i].term_status == 1) {
                            delArr.push(selectArr[i]);//用来存放已上线数据
                        }
                    }
                    if (delArr.length > 0) {
                        toastrCog.error("所选的数据包含已启用的关键词，请重新选择！", 3000);
                        return
                    }
                    $("#delModal").modal("show");
                    tools.delTipRender(selectArr);
                }
            });
            $("#delBtn").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var ids = [];
                for (var i = 0; i < selectArr.length; i++) {
                    ids.push(selectArr[i].id_term);
                }
                $.ajax({
                    type: "post",
                    url: bs.getSysConfig("ZDYW_KEY").value + "/term/removeTermsByIds",
//                    dataType: "json",
                    contentType: 'application/json;charset=UTF-8', //contentType很重要
                    data: JSON.stringify(ids),
                    success: function (data) {
                        if (data.code == 1) {
                            tools.tableRefresh();
                            toastrCog.success("删除成功", 1000)
                        } else {
                            toastrCog.error(data.message, 3000)
                        }
                        $("#delModal").modal("hide");
                    }
                });
            });
        },
        startModel: function () {
            $("#btnStart").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var startArr = [];//用来存放已上线数据
                var stopArr = [];//用来存放未上线数据
                for (var i = 0; i < selectArr.length; i++) {
                    if (selectArr[i].term_status == 1) {
                        startArr.push(selectArr[i]);//保存已上线的数据
                    } else {
                        stopArr.push(selectArr[i]);//保存已上线的数据
                    }
                }
                if (selectArr.length <= 0) {//如果没有选择数据
                    toastrCog.error("请选择要上线的数据！", 3000);
                } else if (startArr.length > 0) {//如果选择了已上线的数据
                    toastrCog.error("所选模型包含已启用 " + tools.getStr(startArr, "term_name") + " 关键词，请重新选择！", 3000);
                } else {
                    tools.tipRender(1, selectArr, "启用");
                }
            });
            $("#startBtn").on("click", function () {
                $("#startBtn").html("请求中...请稍后").prop("disabled", true);
                var code = $("#startModal").attr("data-code");
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var ids = [];
                for (var i = 0; i < selectArr.length; i++) {
                    ids.push(selectArr[i].id_term);
                }
                $.ajax({
                    type: "post",
                    url: bs.getSysConfig("ZDYW_KEY").value + "/term/updateStatusByIds",
                    dataType: "json",
//                    contentType: 'application/json;charset=UTF-8', //contentType很重要
                    data: {
                        idList: ids.join(","),
                        status: code
                    },
                    success: function (data) {
                        if (data.code == 1) {
                            $("#myTable").bootstrapTable('refresh');
                            toastrCog.success("操作成功", 1000)
                        } else {
                            toastrCog.error(data.message, 3000)
                        }
                        $("#startBtn").html("确定").prop("disabled", false);
                        $("#startModal").modal("hide");
                    }
                })
            });
        },
        stopModel: function () {
            $("#btnStop").on("click", function () {
                var selectArr = $("#myTable").bootstrapTable("getSelections");
                var stopArr = [];//用来存放未上线数据
                for (var i = 0; i < selectArr.length; i++) {
                    if (selectArr[i].term_status == 0) {
                        stopArr.push(selectArr[i]);//保存未上线的数据
                    }
                }
                if (selectArr.length <= 0) {
                    toastrCog.error("请选择要停用的数据！", 3000);
                } else if (stopArr.length > 0) {
                    toastrCog.error("所选的数据包含已停用的关键词，请重新选择！", 2000);
                } else {
                    var ids = [];
                    for (var i = 0; i < selectArr.length; i++) {
                        ids.push(selectArr[i].id);
                    }
                    ;
                    tools.tipRender(0, selectArr, "停用");
                }
            });
        },
        delTipRender: function (selectArr) {
            var modalElem = $("#delModal");
            modalElem.modal("show");
            $("#delName").html("您确定要删除所选的" +
                "<span style='color:rgb(50, 136, 226)'>" + selectArr.length + "</span>" +
                "个关键词" +
                "<span style='color:rgb(50, 136, 226)'>" + tools.getStr(selectArr, "term_name") + "</span>吗？");
            modalElem.attr("data-id", tools.getStr(selectArr, "id_term"));
        },
        tipRender: function (type, selectArr, title) {
            var modalElem = $("#startModal");
            modalElem.modal("show");
            modalElem.find(".modal-title").html(title);
            $("#type").html(
                "确定要" + title + "所选的" +
                "<span style='color:rgb(50, 136, 226)'>" + selectArr.length + "</span>" +
                "个关键词" +
                "<span style='color:rgb(50, 136, 226)'>" + tools.getStr(selectArr, "term_name") + "</span>吗？");
            modalElem.attr("data-id", tools.getStr(selectArr, "id_term"));
            modalElem.attr("data-code", type);
        },
        export: function () {
            $("#export").on("click", function () {
                if (tools.tableData.length == 0) {
                    toastrCog.error("没有可导出的数据哦！")
                    return;
                }
                var form = $("#exportForm");
                form.attr("action", bs.getSysConfig("ZDYW_KEY").value + "/resolve/downloadExcel");
                form.find("input[name='id_tree']").val($("#typeAdd").attr("data-id"));
                form.find("input[name='term_name']").val($.trim($("#modelname").val()));
                form.find("input[name='term_status']").val($("#state").val());
                form.find("input[name='create_time_start']").val($("#start").val());
                form.find("input[name='create_time_end']").val($("#end").val());
                form[0].submit();
            })

        },
        updataSelect: function ($obj, val) {
            $obj.val(val);
            $obj.trigger("chosen:updated");
        },
        getStr: function (selectArr, code) {
            var str = "";
            for (var i = 0; i < selectArr.length; i++) {
                str += selectArr[i][code] + ",";
            }
            str = str.substr(0, str.length - 1);
            return str;
        },
        isRepeat: function (arr) {
            var hash = {};
            for (var i in arr) {
                if (hash[arr[i]])
                    return true;
                hash[arr[i]] = true;

            }
            return false;
        }
    };
    var draggables = { //模态框拖动
        init: function () {
            this.draggable($('.modal').not("#addRuleModel"));
        },
        draggable: function (obj) {
            $(obj).draggable();
        }
    };
    var validateFun = {
        init: function () {
            this.initKeyValidatorAdd();
            this.initKeyValidatorEdit();
            this.initKeyValidatorAddType();

        },
        initKeyValidatorAdd: function () {
            $("#addModelForm").jqxValidator({
                rules: [
                    {
                        input: '#keyAdd',
                        message: '关键词不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#keyAdd',
                        message: '关键词只能由汉字，英文，数字组合的50个字符以内，不能以逗号结束 且不能包含空格！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var reg = /^([\u4e00-\u9fa5]|[a-zA-Z0-9]){1,50}(,([\u4e00-\u9fa5]|[a-zA-Z0-9]){1,50})*$/;
                            if ($(input).val() != "") {
                                if (!reg.test($(input).val())) {
                                    return false
                                }
                            }
                            return result;
                        }
                    }
                ],
                hintType: "label"
            });
        },
        initKeyValidatorEdit: function () {
            $("#editModelForm").jqxValidator({
                rules: [
                    {
                        input: '#keyEdit',
                        message: '关键词名称不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#keyEdit',
                        message: '关键词只能由汉字，英文，数字组合，且不能包含空格！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var reg = /^([\u4e00-\u9fa5]|[a-zA-Z0-9])+$/;
                            if ($(input).val() != "") {
                                if (!reg.test($(input).val())) {
                                    return false
                                }
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#keyEdit',
                        message: '关键词名称不能多余' + tools.maxTextLength + '字！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 50) {
                                    return false
                                }
                            }
                            return result;
                        }
                    }, {
                        input: '#keyEdit',
                        message: "关键词名称已经存在!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var validate = true;
                            var url = tools.url + "/term/isExistInProvince";
                            if ($(input).val() != $("#editModal").attr("data-name")) {
                                var data = {
                                    term_name: $(input).val(),
                                    province_code: $("#editModal").attr("data-code")
                                };
                                $.ajax({
                                    url: url,
                                    timeout: 10000,
                                    async: false,
                                    type: 'POST',
                                    data: data,
//                                contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                                    success: function (msg) {
                                        if (msg.data) {
                                            input.focus();
                                            validate = false;
                                        }
                                    }
                                });
                            }
                            return validate;
                        }
                    }
                ],
                hintType: "label"
            });
        },
        initKeyValidatorAddType: function () {
            $("#addTypeForm").jqxValidator({
                rules: [
                    {
                        input: '#modelTypeName',
                        message: '分类名称不能为空',
                        action: 'keyup,blur',
                        rule: 'required'
                    },
                    {
                        input: '#modelTypeName',
                        message: '分类名称不能多余' + tools.maxTextLength + '字！',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val() != "") {
                                if ($(input).val().length > 50) {
                                    return false
                                }
                            }
                            return result;
                        }
                    }, {
                        input: '#modelTypeName',
                        message: '分类名称不能包含空格!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            if ($(input).val().indexOf(" ") > -1) {
                                result = false
                            }
                            return result;
                        }
                    }, {
                        input: '#modelTypeName',
                        message: "分类名称已经存在!",
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var validate = true;
                            var url = tools.url + "/tree/isExistChild";
                            var data = {
                                tree_name: $(input).val(),
                                id_parent: $("#addTypeModal").attr("data-id")
                            };
                            $.ajax({
                                url: url,
                                timeout: 10000,
                                async: false,
                                type: 'POST',
                                data: data,
//                                contentType: "application/json",  //缺失会出现URL编码，无法转成json对象
                                success: function (msg) {
                                    if (msg.data) {
                                        input.focus();
                                        validate = false;
                                    }
                                }
                            });
                            return validate;
                        }
                    }
                ],
                hintType: "label"
            });
        }
    };
    // 批量导入
    var importfile = {
        init: function () {
            importfile.importModalInit();
            importfile.ifile();
            $("#btnAllAdd").on("click", function () {
                $("#importModal").modal("show");
                $("#proModal").val($("#spanId", parent.document).attr("data-procode")).trigger("chosen:updated");
            })
        },
        importModalInit: function () {
            $("#importModal").on("show.bs.modal", function () {
                $('#proModal').val("").trigger("chosen:updated");
                // 初始化文件上传控件
                $("#uploadDiv").html("").append("<div class='file-loading'><input id='uploadFile' name='file' type='file' /></div><div id='errorBlock' class='help-block'></div>");
                $("#uploadFile").fileinput({
                    language: 'zh',
                    uploadUrl: bs.getSysConfig("ZDYW_KEY").value + "/resolve/upload",
                    allowedFileExtensions: ['xls', 'xlsx'],
                    elErrorContainer: '#errorBlock',
                    showPreview: false,
                    showUpload: false,
                    maxFileCount: 1,
                    enctype: 'multipart/form-data',
                    uploadExtraData: function (previewId, index) {
                        var data = {
                            province_code: $('#proModal').val()
                        };
                        return data;
                    }
                }).on("fileuploaded", function (event, data, previewId, index) {
                    var response = data.response;
                    var code = response.code;
                    if (code == "1") {
                        toastrCog.success(response.message);
                    } else {
                        toastrCog.error(response.message);
                    }
                    $("#importModal").modal("hide");
                    //刷新table和左侧树
                    $("#myTable").bootstrapTable("refresh");
                    $("#jstree").jstree("refresh");
                });
            });
        },
        ifile: function () {
            $("#importBtn").off("click").on("click", function () {
                var areaid = $('#proModal').val();
                var file = $("#uploadFile").val();
                if (areaid == "") {
                    toastrCog.error("请选择省份", 2000);
                    return false;
                }
                if (file == "") {
                    toastrCog.error("请选择要上传的文件", 2000);
                    return false;
                }
                // 校验通过上传
                $("#uploadFile").fileinput("upload");
            });
        }
    }
    $(function () {
        var oTable = new TableInit();
        oTable.Init();
        menu.init();
        resize.init();
        tools.init();
        draggables.init();
        validateFun.init();
    })
</script>
</body>
</html>